<template>
  <div class="base-container">
    <!-- <t-form ref="form" :data="queryParams" label-width="80"
      @submit="() => { this.pagination.current = 1; this.queryParams.pageNum = 1; this.getList() }">
      <t-row style="border-bottom: 1px solid #E5E6EB;margin-bottom: 10px">
        <t-col :span="11" class="query-form-inline">
          <t-form-item label="业务名称" name="businessName">
            <t-input v-model="queryParams.businessName" clearable placeholder="请输入项目名称" style="width: 240px" />
          </t-form-item>
          <t-form-item v-if="!hideApproveType" label="业务类型" name="approveType">
            <t-select style="width: 240px" clearable v-model="queryParams.approveType"
              :options="dict.type.approve_type">
            </t-select>
          </t-form-item>
          <t-form-item label="填报单位" name="deptName">
            <t-input v-model="queryParams.deptName" clearable placeholder="请输入填报单位" style="width: 240px" />
          </t-form-item>
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button theme="primary" type="submit"> 查询</t-button>
          <t-button theme="default" variant="outline" type="reset">重置</t-button>
        </t-col>
      </t-row>
    </t-form> -->
    <t-table rowKey="id" :data="data"
      :columns="!hideInfo ? columns : columns.filter(val => { return val.title !== '填报单位' })" hover
      :pagination="pagination" :loading="dataLoading" :sort="sort" :hideSortTips="true">

      <template #approveType="{ row }">
        {{ row.approveType | filterByDict(dict.type.approve_type) }}
      </template>

      <template #approveStatus="{ row }">
        <t-tag v-if="row.approveStatus"
          @click="dialog.header = row.projectName; dialog.standardCategory = row.standardCategory; dialog.objId = row.id; dialog.open_approve_list = true"
          class="cursor-pointer" :theme="handleTheme(row.approveStatus, dict.type.approve_status)" variant="light">
          {{ row.approveStatus | filterByDict(dict.type.approve_status) }}
        </t-tag>
        <t-tag @click="dialog.header = row.projectName; dialog.objId = row.id; dialog.open_approve_list = true"
          class="cursor-pointer" v-else theme="warning" variant="light">未提交
        </t-tag>
      </template>

      <!-- <template #zan="{ row }">
        <t-tag v-if="row.zan === '1'" theme="warning">暂存</t-tag>
        <t-tag v-else theme="warning">待审批</t-tag>
      </template> -->
      <!-- <template #businessId="{ row }">
        <t-link v-if="row.approveType === '1' && row.project.version === '2024'"
          @click="dialog.objId = row.project.id; dialog.header = row.project.projectName; dialog.current_open_project_detail_new = true"
          hover="color" theme="primary">申报详情
        </t-link>
        <t-link v-else-if="row.approveType === '1'"
          @click="dialog.objId = row.project.id; dialog.header = row.project.projectName; dialog.current_open_project_detail = true"
          hover="color" theme="primary">申报详情
        </t-link>

        <t-link v-else-if="row.approveType === '2'"
          @click="dialog.objId = row.project.id; dialog.header = row.project.projectName; dialog.open_outline_detail = true"
          hover="color" theme="primary">大纲详情
        </t-link>
        <t-link v-else-if="row.approveType === '3'" @click="openContractDetail(row)" hover="color" theme="primary">
          合同详情
        </t-link>
        <t-link v-else hover="color" theme="primary">详情</t-link>
      </template> -->
      <template #op="{ row }">
        <t-button @click="dialog.row = row; dialog.open = true" size="small" variant="text" class="t-button-link">
          <t-icon name="edit-1" slot="icon" />
          审批
        </t-button>
      </template>
    </t-table>
    <approve-info :visible.sync="dialog.open" @reload="getList()" :row="dialog.row" v-if="dialog.open">
    </approve-info>

  </div>
</template>

<script>
import ApproveInfo from "./components/approve-info.vue"
export default {
  name: "index",
  dicts: ["approve_type", "project_status", "approve_status"],
  components: {
    ApproveInfo,
  },
  data () {
    return {
      sort: [],
      hideApproveType: false,
      hideInfo: this.$store.state.user.roles.includes("xssc"),
      dialog: {
        open: false,
        header: "",
        row: {},
        data: {},
        open_project_detail: false,
        open_outline_detail: false,
        open_contract_detail: false,
        objId: 0,
        open_approve_list: false,
        tabDefaultValue: '1',
        open_item_detail: false,
        open_new_contract_detail: false,
        current_open_project_detail: false,
        current_open_project_detail_new: false
      },
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        approveType: '',
        businessName: '',
        deptName: ''
      },
      data: [],
      columns: [
        {
          colKey: "talents.name",
          title: "人才姓名",
          align: "center",
          width: 200
        },
        {
          colKey: "businessName",
          title: "业务名称",
          align: "center",
          // ellipsis: true,
          width: 220,
          // sorter: true,
        },
        {
          colKey: "approveType",
          title: "审批业务类型",
          align: "center",
          width: 120
        },
        {
          colKey: "approveStatus",
          title: "审批结果",
          align: "center",
          width: 180,
        },
        {
          colKey: "op",
          title: "操作",
          align: "center",
          width: 200
        },
      ],

      dataLoading: false,
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showPageSize: true,
        pageSizeOptions: [10, 20, 30, 50],
        showFirstAndLastPageBtn: false,
        onChange: (pageInfo) => {
          Object.assign(this.pagination, pageInfo)
          this.queryParams.pageNum = pageInfo.current || 1;
          this.queryParams.pageSize = pageInfo.pageSize;
          this.getList()
        },
      },
    }
  },
  async created () {

    this.getList()
  },
  methods: {

    getList () {
      this.dataLoading = true;
      this.$api.kjrc.approve.myApproveList(this.queryParams).then(response => {
        this.pagination.total = response.total;
        this.data = response.rows;
        this.dataLoading = false;
      }).catch((e) => {
        this.dataLoading = false;
        this.$message.error(e.toString());
      });
    },
    // 审批
    opApproveFun (row) {
      const confirmDia = this.$dialog.confirm({
        header: "系统提示",
        body: `是否审核`,
        theme: "warning",
        onConfirm: ({ e }) => {
          confirmDia.update({
            confirmBtn: {
              loading: true,
            },
          })
          this.$api.kjxm.approve.opApprove({
            id: row.id,
            businessId: row.businessId,
            approveType: row.approveType,
            opinion: "通过",
            approveStatus: "3",
          }).then(
            (res) => {
              this.getList();
              this.$message.success("审核成功");
              // 请求成功后，销毁弹框
              confirmDia.destroy();
            }
          ).catch((e) => {
            confirmDia.update({
              confirmBtn: {
                loading: false,
              },
            })
            this.$message.error(e.toString());
          });
        },
        onClose: ({ e, trigger }) => {
          this.$api.kjxm.approve.opApprove({
            id: row.id,
            businessId: row.businessId,
            approveType: row.approveType,
            opinion: "退回",
            approveStatus: "4",
          }).then(
            (res) => {
              this.getList();
              this.$message.success("审核成功");
              confirmDia.hide();
            }
          ).catch((e) => {
            this.$message.error(e.toString());
          });

        },
      })
      // this.dialog.header = '审批';
      // this.dialog.data = data.row;
      // this.dialog.open_add_edit = true;
    },
    openProjectDetail (row) {
      this.dialog.objId = row.project.id;
      this.dialog.header = row.project.projectName;
      if (row.approveType === '1') {
        this.dialog.tabDefaultValue = '1';
      } else if (row.approveType === '2') {
        this.dialog.tabDefaultValue = '2';
      } else if (row.approveType === '3') {
        this.dialog.tabDefaultValue = '3';
      } else if (row.approveType === '6') {
        this.dialog.tabDefaultValue = '4';
      }
      if (row.project.version === '2024') {
        this.dialog.open_item_detail = true;
      } else {
        this.dialog.open_project_detail = true;
      }
    },
    openContractDetail (row) {
      dialog.objId = row.project.id;
      dialog.header = row.project.projectName;
      if (row.project.version === '2024') {
        this.dialog.open_new_contract_detail = true;
      } else {
        dialog.open_contract_detail = true
      }

    }
  },
}
</script>

<style scoped></style>
